#include "CButton.h"
#include <iostream>

CButton::CButton() {
    Surf_ButtonBG = NULL;
    Select = false;
}

CButton CButton::OnLoad(char* link, int tX, int tY, int Num, char* text, int State) {
    CButton     temp;
    temp.Surf_ButtonBG = CSurface::OnLoad(link);
    temp.X = tX;
    temp.Y = tY;
    temp.GoState = State;
    temp.BNum = Num;
    temp.Title = text;

    return temp;
}

bool CButton::OnLoop(int tX, int tY) {
    if (tX >= X && tX <= Surf_ButtonBG->w + X && tY >= Y && tY <= Surf_ButtonBG->h + Y) {
         Select = true;
         return true;
    }
    Select = false;
    return false;
}

bool CButton::OnClick(int tX, int tY) {
    if (tX >= X && tX <= Surf_ButtonBG->w + X && tY >= Y && tY <= Surf_ButtonBG->h + Y) {
         CAppStateManager::SetActiveAppState(GoState);
         return true;
    }

    return false;
}

bool CButton::OnDraw(SDL_Surface* Surf_Scr, SDL_Surface* ColorButton, TTF_Font* Font) {
    SDL_Surface* Button = Surf_ButtonBG;
    if (!Select)
        CSurface::OnDraw(Button, ColorButton, 5, 6, BNum * 40, 0, 40, 40);
    else
        CSurface::OnDraw(Button, ColorButton, 5, 6, BNum * 40, 40, 40, 40);

    CFont::OnDraw(Font, 1, Title, Button, 60, Surf_ButtonBG->h / 2 - 15);
    CSurface::OnDraw(Surf_Scr, Button, X, Y);

    return true;
}
